package com.sneakxy.mybase4j.platform.provider;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.alibaba.dubbo.config.annotation.Service;
import com.sneakxy.mybase4j.base.provider.BaseProvider;
import com.sneakxy.mybase4j.platform.beans.Router;
import com.sneakxy.mybase4j.platform.repository.RouterRepository;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Service(version = "1.0.0", interfaceClass = IRouterProvider.class)
@org.springframework.stereotype.Service
public class RouterProvider extends BaseProvider<Router, String, RouterRepository> implements IRouterProvider {

	@Autowired
	public RouterProvider(RouterRepository repository) {
		super(repository);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.provider.IRouterProvider#findByAccountId(java.lang.String)
	 */
	@Override
	public List<String> findByAccountId(String account_id) {
		return this.getRepository().findByAccountId(account_id);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.provider.IRouterProvider#updatePermIdToNull(java.lang.String)
	 */
	@Override
	public int updatePermIdToNull(String permId) {
		return this.getRepository().updatePermIdToNull(permId);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.provider.IRouterProvider#findBySearch(java.lang.String, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<Router> findBySearch(String search, Pageable pageable) {
		if(StringUtils.isNotBlank(search)) {
			String s = new StringBuilder().append("%").append(StringUtils.trimToEmpty(search)).append("%").toString();
			return this.getRepository().findBySearch(s, pageable);
		} else {
			return this.getRepository().findAll(pageable);
		}
	}

}
